/*
 * JGO2RDF creates a RDF representation of GAF2 files, which are automatically sourced from GO ftp site.
 * Copyright (C) 2012 Matthew M. Hindle & Artem Lysenko
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package uk.co.jgo2rdf.goa.utils;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author lysenkoa
 *         Wrapper for arrays so they can be used as hash map keys correctly
 *         (equality and hash of arrays is based on their content)
 */
public class ArrayKey<T extends Object> implements Serializable {
    private T[] array = null;

    /**
     *
     */
    public ArrayKey() {
    }

    /**
     * @param array
     */
    public ArrayKey(T[] array) {
        this.array = array;
    }

    /**
     * @return
     */
    public T[] getArray() {
        return array;
    }

    /**
     * @param array
     */
    public void setArray(T[] array) {
        this.array = array;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(array);
    }

    /**
     * @return
     */
    public int size() {
        return array.length;
    }

    @Override
    public boolean equals(Object key) {
        return key instanceof ArrayKey && Arrays.equals(array, ((ArrayKey<?>) key).getArray());
    }
}
